let btn=$('.btn').get(0)
let inp1=$('.inp1')[0]
let inp2=$('.inp2')[0]
let inp3=$('.inp3')[0]
let inp4=$('.inp4')[0]
let inp5=$('.inp5')[0]
let phone=$('.phone')[0]
let note=$('.note')[0]
let setpass=$('.setpass')[0]
let pass=$('.pass')[0]
inp1.onfocus=function(){
  phone.style.display='block'
  phone.innerHTML="🚫设置后不可更改"
  phone.style.color='red'
}

//手机验证
inp1.onblur=function(){
  if (!inp1.value) {
    phone.innerHTML = '🚫不能为空!'
   phone.style.color='red'
   return false
  }
  var re = /^1[3-9]\d{9}$/
  if (!re.test(inp1.value)) {
    phone.innerHTML = '🚫请输入正确手机号！'
    phone.style.color='red'
  }else if (inp1.value.length>11) {
    phone.innerHTML = '🚫手机号不能超过11位数'
    phone.style.color='red'
   }else{
    phone.innerHTML = '✔'
    phone.style.color='green'
    } 
}
//验证码
inp2.onblur=function(){
  if (!inp2.value) {
    note.innerHTML = '🚫不能为空!'
    note.style.color='red'
    return false
  }
  if(!(/^[0-9]{6}$/.test(inp2.value))){
      note.innerHTML='🚫验证码错误'  
      note.style.color='red' 
    }else if (inp2.value.length>6) {
      note.innerHTML = '🚫验证码不能超过6个字符'
      note.style.color='red'
     }else{
      note.innerHTML = '✔'
      note.style.color='green'
      } 
}
//密码强弱
let pa=$('.pa')[0]
let pb=$('.pb')[0]
let pc=$('.pc')[0]
inp3.onblur=function(){
  if(!inp3.value){
    setpass.innerHTML = '🚫不能为空!'
    setpass.style.color='red'
    return false
  }
}
inp3.oninput=function(){
  let weak=/^([a-zA-Z]){6,16}$|^(\d){6,16}$|^((?=[\x21-\x7e]+)[^A-Za-z0-9]){6,16}$|^(?!\2+$)(?!\1+$)[\2\1]{6,7}$|^(?!\3+$)(?!\1+$)[\3\1]{6,7}$|^(?!\3+$)(?!\2+$)[\2\3]{6,7}$|^(?=.*\3)(?=.*\1)(?=.*\2)[a-zA-Z\x21-\x7e\d]{6,7}$/
  let center=/^(?!\d+$)(?![a-zA-Z]+$)[\dA-Za-z]{8,16}$/;
  let strong=/^(?=.*((?=[\x21-\x7e]+)[^A-Za-z0-9]))(?=.*[a-zA-Z])(?=.*[0-9])[^\u4e00-\u9fa5]{8,13}$/; 
  if (weak.test(inp3.value)) {
    pa.style.backgroundColor='orange'
    setpass.innerHTML='✔'
    setpass.style.color='green'
   }
    if(center.test(inp3.value)){
    pb.style.backgroundColor='green'
    setpass.innerHTML='✔'
    setpass.style.color='green'
  }
   if(strong.test(inp3.value)){
    pc.style.backgroundColor='red'
    setpass.innerHTML='✔'
    setpass.style.color='green'
  }
  if(!inp3.value){
    pa.style.backgroundColor='#eee'
    pb.style.backgroundColor='#eee'
    pc.style.backgroundColor='#eee'
  }
}
inp4.oninput=function(){
if(inp3.value===inp4.value){
  pass.innerHTML='✔'
  pass.style.color='green'
}
if(!inp4.value){
    pass.innerHTML=''
  }
}
inp4.onblur=function(){
  if(!inp4.value){
    pass.innerHTML = '🚫不能为空!'
    pass.style.color='red'
    return false
  }
  if(inp3.value!==inp4.value){
    pass.innerHTML='🚫密码不匹配'
  pass.style.color='red'
  }
}



btn.onclick=()=>{
  if (!inp1.value) {
  phone.innerHTML = '🚫不能为空!'
 phone.style.color='red'
}
if (!inp2.value) {
  note.innerHTML = '🚫不能为空!'
  note.style.color='red'
}
if(!inp3.value){
  setpass.innerHTML = '🚫不能为空!'
  setpass.style.color='red'
}
if(!inp4.value){
  pass.innerHTML = '🚫不能为空!'
  pass.style.color='red'
}

  if(phone.innerHTML === '✔'){
    if(note.innerHTML === '✔'){
        if(inp5.checked===true){
        }else{
          alert('请阅读并同意')
          return false
        }
          if(inp3.value===inp4.value){
            localStorage.setItem(inp1.value,inp4.value)
            alert('注册成功')
            location.href='../html/login.html'
        }
      }
    }
 }